//
//  AnimalAndPlantView.m
//  SXH
//
//  Created by 龚啸 on 16/3/18.
//  Copyright © 2016年 lyss. All rights reserved.
//

#import "AnimalAndPlantView.h"

@implementation AnimalAndPlantView
-(instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];// 先调用父类的initWithFrame方法
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        UISegmentedControl * controlView = [[UISegmentedControl alloc ] initWithItems:[NSArray arrayWithObjects:@"科普植物志",@"科普动物志", nil]];
        controlView.selectedSegmentIndex = 0;
        controlView.tintColor = [UIColor clearColor];//去掉颜色,现在整个segment都看不见
        NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],
                                                 NSForegroundColorAttributeName:[UIColor colorWithRed:0.439 green:0.769 blue:0.322 alpha:1.00]};
        [controlView setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性
        NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],
                                                   NSForegroundColorAttributeName: [UIColor colorWithRed:0.204 green:0.204 blue:0.204 alpha:1.00f]};
        [controlView setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
        [controlView addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
        controlView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
        [self addSubview:controlView];
        
        UIView*lineView = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width/2, 5, 1, frame.size.height -10)];
        
        [lineView setBackgroundColor:[UIColor blackColor]];
        lineView.alpha = 0.1;
        [self addSubview:lineView];
    }
    return self;
}
-(void)valueChanged:(UISegmentedControl *)Seg
{
    if (_delegate && [_delegate respondsToSelector:@selector(animalViewSelectedIndex:)]) {
        [self.delegate animalViewSelectedIndex:Seg.selectedSegmentIndex];
    }
}

@end
//{@"科普植物志",@"科普动物志"}